<?php
set_time_limit(0);
include '../c/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
 
$theday=date("Y-m-d", strtotime("-1 day"));
 $theday=date("Y-m-d");

$sql="select id,phone from `zuansu_user`  ";
$query=$mysqli->query($sql);
while ($list=$query->fetch_assoc()) {
  $zslink=$list['id'];
  $phone=$list['phone'];

  $sql="select count(id) as total from `zsu_user_log` where zslink='".$zslink."'  and createtime like '".$theday."%' ";
  echo $sql;
  echo "<br>";
  $querygame=$mysqli->query($sql);
  $getData=$querygame->fetch_assoc();
  $theGame=$getData['total'];

  $newUser=0;
  $joinGameUser=0;

  $sql="select openid from `zsu_user_log` where zslink='".$zslink."'  and createtime like '".$theday."%' ";
  $queryzsu=$mysqli->query($sql);
  while ($list=$queryzsu->fetch_assoc()) {

      $sql="select realname from `y1_users` where openid='".$list['openid']."' limit 0,1 ";
      $queryU=$mysqli->query($sql);
      if($queryU->num_rows>0){
         $getU=$queryU->fetch_assoc();
         if (!empty($getU['realname'])) {
              $newUser++;
         }
      }
       
      $queryF=$mysqli->query($sql);
      if($queryF->num_rows>0){
         $joinGameUser++;
      }
  }


   
   
  $sql="select id from `zsu_total_tong` where zslink='".$zslink."' and theday='".$theday."'  limit 0,1 ";
  $queryTong = $mysqli->query($sql);
  if($queryTong->num_rows>0){


  }else{
     
     $mysqli->query("INSERT INTO `zsu_total_tong` (`id`, `zslink`, `phone`, `newuser`, `lognuser`,`gameuser`, `theday`) VALUES (NULL, '".$zslink."', '".$phone."','".$newUser."','".$joinGameUser."','".$theGame."','".$theday."')");

  }
  
    
}

 

 
$mysqli->close();
    
 
?>